import * as PIXI from 'pixi.js'
import loadAssets from './loadAssets'
/** 设置弹框*/
export const spriteAssetsTexture = async (partName: string): Promise<PIXI.Texture> => {
  const assets = await loadAssets('spriteAssets')
  return assets.textures[partName]
}
export const spriteAssetsSprite = async (
  partName: string,
  options?: { width?: number; height?: number; widthScale?: number; heightScale?: number },
): Promise<PIXI.Sprite | PIXI.NineSliceSprite> => {
  const assets = await loadAssets('spriteAssets')
  const texture = assets.textures[partName]
  if (texture.defaultBorders === undefined) {
    return new PIXI.Sprite(texture)
  } else {
    const nineSliceSprite = new PIXI.NineSliceSprite(texture)
    let spriteWidth = nineSliceSprite.width
    let spriteHeight = nineSliceSprite.height
    if (options) {
      spriteWidth = options.width || (options.widthScale && options.widthScale * spriteWidth) || spriteWidth
      spriteHeight = options.height || (options.heightScale && options.heightScale * spriteHeight) || spriteHeight
    }
    nineSliceSprite.width = spriteWidth
    nineSliceSprite.height = spriteHeight
    return nineSliceSprite
  }
}
